package com.bfly.mall.order.service.impl;

import com.bfly.core.base.service.BaseServiceImpl;
import com.bfly.mall.order.dao.OrderSkuMapper;
import com.bfly.mall.order.entity.OrderSku;
import com.bfly.mall.order.service.IOrderSkuService;
import com.bfly.mall.product.enums.ProductActivityTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 长沙商脉科技有限公司
 * @date 2020/4/19 19:05
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class OrderSkuServiceImpl extends BaseServiceImpl<OrderSku, Integer> implements IOrderSkuService {

    @Autowired
    private OrderSkuMapper skuMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(List<OrderSku> skus) {
        skus.forEach(sku -> {
            super.save(sku);
        });
    }

    @Override
    public OrderSku getOrderSku(String orderNo, String sn) {
        return skuMapper.getSku(orderNo, sn);
    }

    @Override
    public long getActivityBuyCount(int userId, int productId, int activityId, ProductActivityTypeEnum activityType) {
        return skuMapper.getActivityBuyCount(userId,productId,activityId,activityType.getId());
    }
}
